var Global = {
	common: {
		ajaxPath: (window.location + "").split("/")[0] + "//" + (window.location + "").split("/")[2] + "/" + (window.location + "").split("/")[3]
	}
}
$(document).ready(function(){
	var userauthorityName="";
	/**
	 * @note 登陆用户信息
 	 * @author yuancb
     * @create_time 2017-08-1
     */
	jQuery.ajax({ 
		     type: "post", 
		     url: Global.common.ajaxPath +"/users/selInformat.do",
		     //data:{id:1}, 
		     dataType : "json", // 指定返回类型 
		     success: function(data) {
		    	userauthorityName=data.userType.userTypeName;
		    	if(userauthorityName=='admin'||userauthorityName=='superadmin'){
		    		if($('.calendar').length > 0 ){
		    			$('.calendar').fullCalendar({
		    				header: {
		    					left: 'prev,next,today',
		    					center: 'title',
		    					right: 'month,agendaWeek,agendaDay'
		    				},
		    				buttonText:{
		    					today:'跳转到当天'
		    				},
		    				editable: true,
		    				events: [
		    				/*{
		    					title: '全天事项',
		    					start: new Date(y, m, 1)
		    				},
		    				// {
		    				// 	title: '长距离项目',
		    				// 	start: new Date(y, m, d-5),
		    				// 	end: new Date(y, m, d-2)
		    				// },
		    				{
		    					id: 999,
		    					title: '重复项目',
		    					start: new Date(y, m, d-3, 16, 0),
		    					allDay: false
		    				},
		    				{
		    					id: 999,
		    					title: '重复项目',
		    					start: new Date(y, m, d+4, 16, 0),
		    					allDay: false
		    				},
		    				{
		    					title: '会议',
		    					start: new Date(y, m, d, 10, 30),
		    					allDay: false
		    				},
		    				{
		    					title: '午餐',
		    					start: new Date(y, m, d, 19, 0),
		    					end: new Date(y, m, d, 14, 0),
		    					allDay: false
		    				},
		    				{
		    					title: '早班：8:00-12:00',
		    					start: new Date(y, m, d+1, 19, 0),
		    					end: new Date(y, m, d+1, 22, 30),
		    					allDay: false
		    				},
		    				{
		    					title: '早班：8:00-12:00',
		    					start: new Date(y, m, 28),
		    					end: new Date(y, m, 29),
		    					url: 'http://www.google.com/'
		    				}*/
		    				],
		    				viewDisplay: function (view) {
		    					//alert(view);
		    		            //动态把数据查出，按照月份动态查询
		    		            var starTime = $.fullCalendar.formatDate(view.start, "yyyy-MM-dd");
//		    		            var viewStartd = viewStart.getDate();
//		    		        	var viewStartm = viewStart.getMonth()+1;
//		    		        	var viewStarty = viewStart.getFullYear();
		    		            var viewStartArray=starTime.split("-");
		    		            var viewStartd=viewStartArray[2];
		    		            var viewStartm=viewStartArray[1];
		    		            var viewStarty=viewStartArray[0];
		    		            
		    		            var endTime = $.fullCalendar.formatDate(view.end, "yyyy-MM-dd");
		    		            //alert(starTime+"--"+endTime);
		    		            $("#calendar").fullCalendar('removeEvents');
		    		            //通过post 请求一般处理程序来返回需要展现的信息(start与end为需要传递的参数，在本文中没有用到可以忽略)
		    		            $.post(Global.common.ajaxPath+"/schedulingDistribute/selectALL.do", {starTime:starTime,endTime:endTime,}, function (data) {
		    		            	
		    		            	/*if(viewStartm==1||viewStartm==3||viewStartm==5||viewStartm==7||viewStartm==8||viewStartm==10||viewStartm==12){
		    		            		
		    		            		for(var i=1;i<=31;i++) {
		    		            			var obj = new Object();
		    		            			obj.id = 1;
		    		            			obj.title = '早班：8:00-12:00';
		    		            			obj.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj, true);
		    		            			var obj1 = new Object();
		    		            			obj1.id = 1;
		    		            			obj1.title = '晚班：14:00-16:00';
		    		            			obj1.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj1, true);
		    		            		}
		    		            		
		    		            	}else if(viewStartm==4||viewStartm==6||viewStartm==9||viewStartm==11){
		    		            		for(var i=1;i<=30;i++) {
		    		            			var obj = new Object();
		    		            			obj.id = 1;
		    		            			obj.title = '早班：8:00-12:00';
		    		            			obj.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj, true);
		    		            			var obj1 = new Object();
		    		            			obj1.id = 1;
		    		            			obj1.title = '晚班：14:00-16:00';
		    		            			obj1.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj1, true);
		    		            		}
		    		            		
		    		            	}else if((((viewStarty % 4)==0) && ((viewStarty % 100)!=0) || ((viewStarty % 400)==0))&&viewStartm==2){
		    		            		for(var i=1;i<=29;i++) {
		    		            			var obj = new Object();
		    		            			obj.id = 1;
		    		            			obj.title = '早班：8:00-12:00';
		    		            			obj.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj, true);
		    		            			var obj1 = new Object();
		    		            			obj1.id = 1;
		    		            			obj1.title = '晚班：14:00-16:00';
		    		            			obj1.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj1, true);
		    		            		}
		    		            	}else if(!(((viewStarty % 4)==0) && ((viewStarty % 100)!=0) || ((viewStarty % 400)==0))&&viewStartm==2){
		    		            		for(var i=1;i<=28;i++) {
		    		            			var obj = new Object();
		    		            			obj.id = 1;
		    		            			obj.title = '早班：8:00-12:00';
		    		            			obj.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj, true);
		    		            			var obj1 = new Object();
		    		            			obj1.id = 1;
		    		            			obj1.title = '晚班：14:00-16:00';
		    		            			obj1.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj1, true);
		    		            		}
		    		            	}*/
		    		                var resultCollection = jQuery.parseJSON(data.t);
		    		                $.each(data.t, function (index, term) {
		    		                	var shedulingTime = term.shedulingDate;
		    		                	var shedulingTimeArray = shedulingTime.split("-");
		    		                	var viewStartday=shedulingTimeArray[2];
		    		     	            var viewStartmon=shedulingTimeArray[1];
		    		     	            var viewStartyear=shedulingTimeArray[0];
		    		     	            //alert(term.nightWatchkeeper);
		    		                	if(term.morningWatchkeeper){
		    		                		var obj = new Object();
		    		                		obj.id = term.distributeId;
		    		                		obj.title = '早班：'+term.morningWatchkeeper;
		    		                		obj.start=new Date(viewStartyear, viewStartmon-1, viewStartday);
		    		                		$(".calendar").fullCalendar('renderEvent', obj, true);
		    		                	}
		    		                	if(term.nightWatchkeeper){
		    		                		var obj = new Object();
		    		                		obj.id = term.distributeId;
		    		                		obj.title = '晚班：'+term.nightWatchkeeper;
		    		                		obj.start=new Date(viewStartyear, viewStartmon-1, viewStartday);
		    		                		$(".calendar").fullCalendar('renderEvent', obj, true);
		    		                	}
		    		                });

		    		            }); //把从后台取出的数据进行封装以后在页面上以fullCalendar的方式进行显示
		    		        },
		    		        dayClick: function (date, allDay, jsEvent, view) {
		    		        	console.log(jsEvent);
		    		        	var selectdate = $.fullCalendar.formatDate(date, "yyyy-MM-dd");//选择当前日期的时间转换
		    		            $("#reservebox").dialog({
		    		            	autoOpen: false,
		    		                height: 300,
		    		                width: 400,
		    		                title: '排班管理' + selectdate,
		    		                modal: true,
		    		                position: "center",
		    		                draggable: false,
		    		                beforeClose: function (event, ui) {
		    		                        //$.validationEngine.closePrompt("#meeting");
		    		                        //$.validationEngine.closePrompt("#start");
		    		                        //$.validationEngine.closePrompt("#end");
		    		                 },
		    		                 timeFormat: 'HH:mm{ - HH:mm}',
		    		                 buttons: {
		    		                	 "关闭": function () {
		    		                            $(this).dialog("close");
		    		                            $("#morningWatchkeeper").val(''); //早班值班人员
		    	                                $("#nightWatchkeeper").val('');//晚班值班人员
		    		                     },
		    		                     "提交": function () {
		    		                    	 var morningWatchkeeper = $("#morningWatchkeeper").val(); //早班值班人员
		    		                         var nightWatchkeeper = $("#nightWatchkeeper").val(); //晚班值班人员
		    		                         var id2;
		    		                         var startdate = $.fullCalendar.parseDate(selectdate);//时间和日期拼接
		    		                         //alert(startdate);
		    		                         //var enddate = $.fullCalendar.parseDate(enddatestr);
		    		                         var schdata = { morningWatchkeeper: morningWatchkeeper, nightWatchkeeper: nightWatchkeeper, selectdate: selectdate };
		    		                         $.ajax({
		    		                        	 type: "POST", //使用post方法访问后台
		    		                             url: Global.common.ajaxPath+"/schedulingDistribute/add.do", //要访问的后台地址
		    		                             data: schdata, //要发送的数据
		    		                             success: function (data) {
		    		                            	 //对话框里面的数据提交完成，data为操作结果
//		    		                                 id2 = data;
		    		                            	 if(morningWatchkeeper){
		    		                            		 var selectdateArray = selectdate.split("-");
		    		                            		 var viewStartday1=selectdateArray[2];
		    		                            		 var viewStartmon1=selectdateArray[1];
		    		                            		 var viewStartyear1=selectdateArray[0];
		    		                            		 var schdata2 = { title:'早班：'+morningWatchkeeper ,start:new Date(viewStartyear1,viewStartmon1-1,viewStartday1) };
		    		                            		 $('.calendar').fullCalendar('renderEvent', schdata2, true);
		    		                            	 }
		    		                            	 if(nightWatchkeeper){
		    		                            		 var selectdateArray = selectdate.split("-");
		    		                            		 var viewStartday1=selectdateArray[2];
		    		                            		 var viewStartmon1=selectdateArray[1];
		    		                            		 var viewStartyear1=selectdateArray[0];
		    		                            		 var schdata1 = { title:'晚班：'+nightWatchkeeper ,start:new Date(viewStartyear1,viewStartmon1-1,viewStartday1) };
		    		                     	             $("#calendar").fullCalendar('removeEvents',{start:new Date(viewStartyear1,viewStartmon1-1,viewStartday1) },true);
		    		                            		 $('.calendar').fullCalendar('renderEvent', schdata1, true);
		    		                            		 
		    		                            	 }
		    		                                 $("#morningWatchkeeper").val(''); //早班值班人员
		    		                                 $("#nightWatchkeeper").val(''); //晚班值班人员
		    		                                 //location.reload();
		    		                                
		    		                             }
		    		                         });
		    		                         $(this).dialog("close");

		    		                     }
		    		                 }
		    		            });
		    		            $("#reservebox").dialog("open");
		    		            return false;
		    		        },
		    		        eventClick: function (event) {
		    		        	console.log(event);
		    		        	var morningWatchkeeper =""; //早班值班人员
		    	                var nightWatchkeeper = ""; //晚班值班人员
		    		        	var selectdate = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd");//选择当前日期的时间转换
		    		        	var distributeId = event.id;
		    		            $.post(Global.common.ajaxPath+"/schedulingDistribute/selectOne.do", {distributeId :distributeId}, function (data) {
		    		            	if(data.t.morningWatchkeeper){
		    		            		$("#morningWatchkeeper").val(data.t.morningWatchkeeper); //早班值班人员
		    		            	}
		    		            	if(data.t.nightWatchkeeper){
		    		            		$("#nightWatchkeeper").val(data.t.nightWatchkeeper); //晚班值班人员
		    		            	}
		    		            	$("#reservebox").dialog({
		    			            	autoOpen: false,
		    			                height: 300,
		    			                width: 400,
		    			                title: '排班管理' + selectdate,
		    			                modal: true,
		    			                position: "center",
		    			                draggable: false,
		    			                beforeClose: function (event, ui) {
		    			                        //$.validationEngine.closePrompt("#meeting");
		    			                        //$.validationEngine.closePrompt("#start");
		    			                        //$.validationEngine.closePrompt("#end");
		    			                 },
		    			                 timeFormat: 'HH:mm{ - HH:mm}',
		    			                 buttons: {
		    			                	 "关闭": function () {
		    			                            $(this).dialog("close");
		    			                            $("#morningWatchkeeper").val(''); //早班值班人员
		    		                                $("#nightWatchkeeper").val('');//晚班值班人员
		    			                     },
		    			                     "删除": function () {
		    			                         var aa = window.confirm("警告：确定要删除记录，删除后无法恢复！");
		    			                         if (aa) {
		    			                        	 var para = { distributeId:distributeId };
		    			                        	 $.ajax({
		    			                        		 type: "POST", //使用post方法访问后台
		    			                                 url: Global.common.ajaxPath+"/schedulingDistribute/delete.do", //要访问的后台地址
		    			                                 data: para, //要发送的数据
		    			                                 success: function (data) {
		    			                                        //对话框里面的数据提交完成，data为操作结果
		    			                                	 $('.calendar').fullCalendar('removeEvents', distributeId);
		    			                                	 $("#morningWatchkeeper").val(''); //早班值班人员
		    				                                 $("#nightWatchkeeper").val(''); 
		    			                                 }
		    			                             });
		    			                         }
		    			                         $(this).dialog("close");
		    			                         $("#morningWatchkeeper").val(''); //早班值班人员
		    		                             $("#nightWatchkeeper").val('');//晚班值班人员
		    			                     },
		    			                     "更新": function () {
		    			                    	 morningWatchkeeper = $("#morningWatchkeeper").val(); //早班值班人员
		    			                         nightWatchkeeper = $("#nightWatchkeeper").val(); //晚班值班人员
		    			                         //var id2;
		    			                         var startdate = $.fullCalendar.parseDate(selectdate);//时间和日期拼接
		    			                         //alert(startdate);
		    			                         //var enddate = $.fullCalendar.parseDate(enddatestr);
		    			                         var schdata = { distributeId:distributeId ,morningWatchkeeper: morningWatchkeeper, nightWatchkeeper: nightWatchkeeper};
		    			                         $.ajax({
		    			                        	 type: "POST", //使用post方法访问后台
		    			                             url: Global.common.ajaxPath+"/schedulingDistribute/edit.do", //要访问的后台地址
		    			                             data: schdata, //要发送的数据
		    			                             success: function (data) {
		    			                            	 if(morningWatchkeeper){
		    			                            		 var selectdateArray = selectdate.split("-");
		    			                            		 var viewStartday2=selectdateArray[2];
		    			                            		 var viewStartmon2=selectdateArray[1];
		    			                            		 var viewStartyear2=selectdateArray[0];
		    			                            		 var schdata2 = { title:'早班：'+morningWatchkeeper ,start:new Date(viewStartyear1,viewStartmon1-1,viewStartday1) };
		    			                            		 $('.calendar').fullCalendar('renderEvent', schdata2, true);
		    			                            	 }
		    			                            	 if(nightWatchkeeper){
		    			                            		 var selectdateArray = selectdate.split("-");
		    			                            		 var viewStartday2=selectdateArray[2];
		    			                            		 var viewStartmon2=selectdateArray[1];
		    			                            		 var viewStartyear2=selectdateArray[0];
		    			                            		 var schdata1 = { title:'晚班：'+nightWatchkeeper ,start:new Date(viewStartyear1,viewStartmon1-1,viewStartday1) };
		    			                            		 $('.calendar').fullCalendar('renderEvent', schdata1, true);
		    			                            		 
		    			                            	 }
		    			                                 $("#morningWatchkeeper").val(''); //早班值班人员
		    			                                 $("#nightWatchkeeper").val(''); //晚班值班人员
		    			    				             //location.reload();

		    			                             }
		    			                         });
		    			                         $(this).dialog("close");
		    			                     }
		    			                 }
		    			            });
		    			            $("#reservebox").dialog("open");
		    			            return false;
		    		            });
		    		        },
		    		        eventMouseover: function (calEvent, jsEvent, view) {
		    		        	console.log(calEvent);
		    	                var fstart = $.fullCalendar.formatDate(calEvent.start, "yyyy/MM/dd");
		    	                var fend = $.fullCalendar.formatDate(calEvent.end, "yyyy/MM/dd");
		    	                $(this).attr('title', fstart  + " : " + calEvent.title);
		    	                $(this).css('font-weight', 'normal');
		    	                $(this).tooltip({
		    	                    effect: 'toggle',
		    	                    cancelDefault: true
		    	                });
		    	            },
		    		        
		    			});
		    		}
		    		
		    	}else{
		    		if($('.calendar').length > 0 ){
		    			$('.calendar').fullCalendar({
		    				header: {
		    					left: 'prev,next,today',
		    					center: 'title',
		    					right: 'month,agendaWeek,agendaDay'
		    				},
		    				buttonText:{
		    					today:'跳转到当天'
		    				},
		    				editable: true,
		    				events: [
		    				/*{
		    					title: '全天事项',
		    					start: new Date(y, m, 1)
		    				},
		    				// {
		    				// 	title: '长距离项目',
		    				// 	start: new Date(y, m, d-5),
		    				// 	end: new Date(y, m, d-2)
		    				// },
		    				{
		    					id: 999,
		    					title: '重复项目',
		    					start: new Date(y, m, d-3, 16, 0),
		    					allDay: false
		    				},
		    				{
		    					id: 999,
		    					title: '重复项目',
		    					start: new Date(y, m, d+4, 16, 0),
		    					allDay: false
		    				},
		    				{
		    					title: '会议',
		    					start: new Date(y, m, d, 10, 30),
		    					allDay: false
		    				},
		    				{
		    					title: '午餐',
		    					start: new Date(y, m, d, 19, 0),
		    					end: new Date(y, m, d, 14, 0),
		    					allDay: false
		    				},
		    				{
		    					title: '早班：8:00-12:00',
		    					start: new Date(y, m, d+1, 19, 0),
		    					end: new Date(y, m, d+1, 22, 30),
		    					allDay: false
		    				},
		    				{
		    					title: '早班：8:00-12:00',
		    					start: new Date(y, m, 28),
		    					end: new Date(y, m, 29),
		    					url: 'http://www.google.com/'
		    				}*/
		    				],
		    				viewDisplay: function (view) {
		    					//alert(view);
		    		            //动态把数据查出，按照月份动态查询
		    		            var starTime = $.fullCalendar.formatDate(view.start, "yyyy-MM-dd");
//		    		            var viewStartd = viewStart.getDate();
//		    		        	var viewStartm = viewStart.getMonth()+1;
//		    		        	var viewStarty = viewStart.getFullYear();
		    		            var viewStartArray=starTime.split("-");
		    		            var viewStartd=viewStartArray[2];
		    		            var viewStartm=viewStartArray[1];
		    		            var viewStarty=viewStartArray[0];
		    		            
		    		            var endTime = $.fullCalendar.formatDate(view.end, "yyyy-MM-dd");
		    		            //alert(starTime+"--"+endTime);
		    		            $("#calendar").fullCalendar('removeEvents');
		    		            //通过post 请求一般处理程序来返回需要展现的信息(start与end为需要传递的参数，在本文中没有用到可以忽略)
		    		            $.post(Global.common.ajaxPath+"/schedulingDistribute/selectALL.do", {starTime:starTime,endTime:endTime,}, function (data) {
		    		            	
		    		            	/*if(viewStartm==1||viewStartm==3||viewStartm==5||viewStartm==7||viewStartm==8||viewStartm==10||viewStartm==12){
		    		            		
		    		            		for(var i=1;i<=31;i++) {
		    		            			var obj = new Object();
		    		            			obj.id = 1;
		    		            			obj.title = '早班：8:00-12:00';
		    		            			obj.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj, true);
		    		            			var obj1 = new Object();
		    		            			obj1.id = 1;
		    		            			obj1.title = '晚班：14:00-16:00';
		    		            			obj1.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj1, true);
		    		            		}
		    		            		
		    		            	}else if(viewStartm==4||viewStartm==6||viewStartm==9||viewStartm==11){
		    		            		for(var i=1;i<=30;i++) {
		    		            			var obj = new Object();
		    		            			obj.id = 1;
		    		            			obj.title = '早班：8:00-12:00';
		    		            			obj.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj, true);
		    		            			var obj1 = new Object();
		    		            			obj1.id = 1;
		    		            			obj1.title = '晚班：14:00-16:00';
		    		            			obj1.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj1, true);
		    		            		}
		    		            		
		    		            	}else if((((viewStarty % 4)==0) && ((viewStarty % 100)!=0) || ((viewStarty % 400)==0))&&viewStartm==2){
		    		            		for(var i=1;i<=29;i++) {
		    		            			var obj = new Object();
		    		            			obj.id = 1;
		    		            			obj.title = '早班：8:00-12:00';
		    		            			obj.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj, true);
		    		            			var obj1 = new Object();
		    		            			obj1.id = 1;
		    		            			obj1.title = '晚班：14:00-16:00';
		    		            			obj1.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj1, true);
		    		            		}
		    		            	}else if(!(((viewStarty % 4)==0) && ((viewStarty % 100)!=0) || ((viewStarty % 400)==0))&&viewStartm==2){
		    		            		for(var i=1;i<=28;i++) {
		    		            			var obj = new Object();
		    		            			obj.id = 1;
		    		            			obj.title = '早班：8:00-12:00';
		    		            			obj.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj, true);
		    		            			var obj1 = new Object();
		    		            			obj1.id = 1;
		    		            			obj1.title = '晚班：14:00-16:00';
		    		            			obj1.start=new Date(viewStarty, viewStartm-1, i);
		    		            			$("#calendar").fullCalendar('renderEvent', obj1, true);
		    		            		}
		    		            	}*/
		    		                var resultCollection = jQuery.parseJSON(data.t);
		    		                $.each(data.t, function (index, term) {
		    		                	var shedulingTime = term.shedulingDate;
		    		                	var shedulingTimeArray = shedulingTime.split("-");
		    		                	var viewStartday=shedulingTimeArray[2];
		    		     	            var viewStartmon=shedulingTimeArray[1];
		    		     	            var viewStartyear=shedulingTimeArray[0];
		    		     	            //alert(term.nightWatchkeeper);
		    		                	if(term.morningWatchkeeper){
		    		                		var obj = new Object();
		    		                		obj.id = term.distributeId;
		    		                		obj.title = '早班：'+term.morningWatchkeeper;
		    		                		obj.start=new Date(viewStartyear, viewStartmon-1, viewStartday);
		    		                		$(".calendar").fullCalendar('renderEvent', obj, true);
		    		                	}
		    		                	if(term.nightWatchkeeper){
		    		                		var obj = new Object();
		    		                		obj.id = term.distributeId;
		    		                		obj.title = '晚班：'+term.nightWatchkeeper;
		    		                		obj.start=new Date(viewStartyear, viewStartmon-1, viewStartday);
		    		                		$(".calendar").fullCalendar('renderEvent', obj, true);
		    		                	}
		    		                });

		    		            }); //把从后台取出的数据进行封装以后在页面上以fullCalendar的方式进行显示
		    		        },
		    		       
		    		        eventMouseover: function (calEvent, jsEvent, view) {
		    		        	console.log(calEvent);
		    	                var fstart = $.fullCalendar.formatDate(calEvent.start, "yyyy/MM/dd");
		    	                var fend = $.fullCalendar.formatDate(calEvent.end, "yyyy/MM/dd");
		    	                $(this).attr('title', fstart  + " : " + calEvent.title);
		    	                $(this).css('font-weight', 'normal');
		    	                $(this).tooltip({
		    	                    effect: 'toggle',
		    	                    cancelDefault: true
		    	                });
		    	            },
		    		        
		    			});
		    		}
		    	}
		    	
		     }, 
		     	error : function() 
		     { 
		     	alert("请求失败！"); 
		     } 
    }); 
	
	var date = new Date();
	var d = date.getDate();
	var m = date.getMonth()+1;
	var y = date.getFullYear();
	//alert(y);
	/*if($('.calendar').length > 0 ){
		$('.calendar').fullCalendar({
			header: {
				left: 'prev,next,today',
				center: 'title',
				right: 'month,agendaWeek,agendaDay'
			},
			buttonText:{
				today:'跳转到当天'
			},
			editable: true,
			events: [
			{
				title: '全天事项',
				start: new Date(y, m, 1)
			},
			// {
			// 	title: '长距离项目',
			// 	start: new Date(y, m, d-5),
			// 	end: new Date(y, m, d-2)
			// },
			{
				id: 999,
				title: '重复项目',
				start: new Date(y, m, d-3, 16, 0),
				allDay: false
			},
			{
				id: 999,
				title: '重复项目',
				start: new Date(y, m, d+4, 16, 0),
				allDay: false
			},
			{
				title: '会议',
				start: new Date(y, m, d, 10, 30),
				allDay: false
			},
			{
				title: '午餐',
				start: new Date(y, m, d, 19, 0),
				end: new Date(y, m, d, 14, 0),
				allDay: false
			},
			{
				title: '早班：8:00-12:00',
				start: new Date(y, m, d+1, 19, 0),
				end: new Date(y, m, d+1, 22, 30),
				allDay: false
			},
			{
				title: '早班：8:00-12:00',
				start: new Date(y, m, 28),
				end: new Date(y, m, 29),
				url: 'http://www.google.com/'
			}
			],
			viewDisplay: function (view) {
				//alert(view);
	            //动态把数据查出，按照月份动态查询
	            var starTime = $.fullCalendar.formatDate(view.start, "yyyy-MM-dd");
//	            var viewStartd = viewStart.getDate();
//	        	var viewStartm = viewStart.getMonth()+1;
//	        	var viewStarty = viewStart.getFullYear();
	            var viewStartArray=starTime.split("-");
	            var viewStartd=viewStartArray[2];
	            var viewStartm=viewStartArray[1];
	            var viewStarty=viewStartArray[0];
	            
	            var endTime = $.fullCalendar.formatDate(view.end, "yyyy-MM-dd");
	            //alert(starTime+"--"+endTime);
	            $("#calendar").fullCalendar('removeEvents');
	            //通过post 请求一般处理程序来返回需要展现的信息(start与end为需要传递的参数，在本文中没有用到可以忽略)
	            $.post(Global.common.ajaxPath+"/schedulingDistribute/selectALL.do", {starTime:starTime,endTime:endTime,}, function (data) {
	            	
	            	if(viewStartm==1||viewStartm==3||viewStartm==5||viewStartm==7||viewStartm==8||viewStartm==10||viewStartm==12){
	            		
	            		for(var i=1;i<=31;i++) {
	            			var obj = new Object();
	            			obj.id = 1;
	            			obj.title = '早班：8:00-12:00';
	            			obj.start=new Date(viewStarty, viewStartm-1, i);
	            			$("#calendar").fullCalendar('renderEvent', obj, true);
	            			var obj1 = new Object();
	            			obj1.id = 1;
	            			obj1.title = '晚班：14:00-16:00';
	            			obj1.start=new Date(viewStarty, viewStartm-1, i);
	            			$("#calendar").fullCalendar('renderEvent', obj1, true);
	            		}
	            		
	            	}else if(viewStartm==4||viewStartm==6||viewStartm==9||viewStartm==11){
	            		for(var i=1;i<=30;i++) {
	            			var obj = new Object();
	            			obj.id = 1;
	            			obj.title = '早班：8:00-12:00';
	            			obj.start=new Date(viewStarty, viewStartm-1, i);
	            			$("#calendar").fullCalendar('renderEvent', obj, true);
	            			var obj1 = new Object();
	            			obj1.id = 1;
	            			obj1.title = '晚班：14:00-16:00';
	            			obj1.start=new Date(viewStarty, viewStartm-1, i);
	            			$("#calendar").fullCalendar('renderEvent', obj1, true);
	            		}
	            		
	            	}else if((((viewStarty % 4)==0) && ((viewStarty % 100)!=0) || ((viewStarty % 400)==0))&&viewStartm==2){
	            		for(var i=1;i<=29;i++) {
	            			var obj = new Object();
	            			obj.id = 1;
	            			obj.title = '早班：8:00-12:00';
	            			obj.start=new Date(viewStarty, viewStartm-1, i);
	            			$("#calendar").fullCalendar('renderEvent', obj, true);
	            			var obj1 = new Object();
	            			obj1.id = 1;
	            			obj1.title = '晚班：14:00-16:00';
	            			obj1.start=new Date(viewStarty, viewStartm-1, i);
	            			$("#calendar").fullCalendar('renderEvent', obj1, true);
	            		}
	            	}else if(!(((viewStarty % 4)==0) && ((viewStarty % 100)!=0) || ((viewStarty % 400)==0))&&viewStartm==2){
	            		for(var i=1;i<=28;i++) {
	            			var obj = new Object();
	            			obj.id = 1;
	            			obj.title = '早班：8:00-12:00';
	            			obj.start=new Date(viewStarty, viewStartm-1, i);
	            			$("#calendar").fullCalendar('renderEvent', obj, true);
	            			var obj1 = new Object();
	            			obj1.id = 1;
	            			obj1.title = '晚班：14:00-16:00';
	            			obj1.start=new Date(viewStarty, viewStartm-1, i);
	            			$("#calendar").fullCalendar('renderEvent', obj1, true);
	            		}
	            	}
	                var resultCollection = jQuery.parseJSON(data.t);
	                $.each(data.t, function (index, term) {
	                	var shedulingTime = term.shedulingDate;
	                	var shedulingTimeArray = shedulingTime.split("-");
	                	var viewStartday=shedulingTimeArray[2];
	     	            var viewStartmon=shedulingTimeArray[1];
	     	            var viewStartyear=shedulingTimeArray[0];
	     	            //alert(term.nightWatchkeeper);
	                	if(term.morningWatchkeeper){
	                		var obj = new Object();
	                		obj.id = term.distributeId;
	                		obj.title = '早班：'+term.morningWatchkeeper;
	                		obj.start=new Date(viewStartyear, viewStartmon-1, viewStartday);
	                		$(".calendar").fullCalendar('renderEvent', obj, true);
	                	}
	                	if(term.nightWatchkeeper){
	                		var obj = new Object();
	                		obj.id = term.distributeId;
	                		obj.title = '晚班：'+term.nightWatchkeeper;
	                		obj.start=new Date(viewStartyear, viewStartmon-1, viewStartday);
	                		$(".calendar").fullCalendar('renderEvent', obj, true);
	                	}
	                });

	            }); //把从后台取出的数据进行封装以后在页面上以fullCalendar的方式进行显示
	        },
	        dayClick: function (date, allDay, jsEvent, view) {
	        	console.log(jsEvent);
	        	var selectdate = $.fullCalendar.formatDate(date, "yyyy-MM-dd");//选择当前日期的时间转换
	            $("#reservebox").dialog({
	            	autoOpen: false,
	                height: 300,
	                width: 400,
	                title: '排班管理' + selectdate,
	                modal: true,
	                position: "center",
	                draggable: false,
	                beforeClose: function (event, ui) {
	                        //$.validationEngine.closePrompt("#meeting");
	                        //$.validationEngine.closePrompt("#start");
	                        //$.validationEngine.closePrompt("#end");
	                 },
	                 timeFormat: 'HH:mm{ - HH:mm}',
	                 buttons: {
	                	 "关闭": function () {
	                            $(this).dialog("close");
	                            $("#morningWatchkeeper").val(''); //早班值班人员
                                $("#nightWatchkeeper").val('');//晚班值班人员
	                     },
	                     "提交": function () {
	                    	 var morningWatchkeeper = $("#morningWatchkeeper").val(); //早班值班人员
	                         var nightWatchkeeper = $("#nightWatchkeeper").val(); //晚班值班人员
	                         var id2;
	                         var startdate = $.fullCalendar.parseDate(selectdate);//时间和日期拼接
	                         //alert(startdate);
	                         //var enddate = $.fullCalendar.parseDate(enddatestr);
	                         var schdata = { morningWatchkeeper: morningWatchkeeper, nightWatchkeeper: nightWatchkeeper, selectdate: selectdate };
	                         $.ajax({
	                        	 type: "POST", //使用post方法访问后台
	                             url: Global.common.ajaxPath+"/schedulingDistribute/add.do", //要访问的后台地址
	                             data: schdata, //要发送的数据
	                             success: function (data) {
	                            	 //对话框里面的数据提交完成，data为操作结果
//	                                 id2 = data;
	                            	 if(morningWatchkeeper){
	                            		 var selectdateArray = selectdate.split("-");
	                            		 var viewStartday1=selectdateArray[2];
	                            		 var viewStartmon1=selectdateArray[1];
	                            		 var viewStartyear1=selectdateArray[0];
	                            		 var schdata2 = { title:'早班：'+morningWatchkeeper ,start:new Date(viewStartyear1,viewStartmon1-1,viewStartday1) };
	                            		 $('.calendar').fullCalendar('renderEvent', schdata2, true);
	                            	 }
	                            	 if(nightWatchkeeper){
	                            		 var selectdateArray = selectdate.split("-");
	                            		 var viewStartday1=selectdateArray[2];
	                            		 var viewStartmon1=selectdateArray[1];
	                            		 var viewStartyear1=selectdateArray[0];
	                            		 var schdata1 = { title:'晚班：'+nightWatchkeeper ,start:new Date(viewStartyear1,viewStartmon1-1,viewStartday1) };
	                     	             $("#calendar").fullCalendar('removeEvents',{start:new Date(viewStartyear1,viewStartmon1-1,viewStartday1) },true);
	                            		 $('.calendar').fullCalendar('renderEvent', schdata1, true);
	                            		 
	                            	 }
	                                 $("#morningWatchkeeper").val(''); //早班值班人员
	                                 $("#nightWatchkeeper").val(''); //晚班值班人员
	                                 //location.reload();
	                                
	                             }
	                         });
	                         $(this).dialog("close");

	                     }
	                 }
	            });
	            $("#reservebox").dialog("open");
	            return false;
	        },
	        eventClick: function (event) {
	        	console.log(event);
	        	var morningWatchkeeper =""; //早班值班人员
                var nightWatchkeeper = ""; //晚班值班人员
	        	var selectdate = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd");//选择当前日期的时间转换
	        	var distributeId = event.id;
	            $.post(Global.common.ajaxPath+"/schedulingDistribute/selectOne.do", {distributeId :distributeId}, function (data) {
	            	if(data.t.morningWatchkeeper){
	            		$("#morningWatchkeeper").val(data.t.morningWatchkeeper); //早班值班人员
	            	}
	            	if(data.t.nightWatchkeeper){
	            		$("#nightWatchkeeper").val(data.t.nightWatchkeeper); //晚班值班人员
	            	}
	            	$("#reservebox").dialog({
		            	autoOpen: false,
		                height: 300,
		                width: 400,
		                title: '排班管理' + selectdate,
		                modal: true,
		                position: "center",
		                draggable: false,
		                beforeClose: function (event, ui) {
		                        //$.validationEngine.closePrompt("#meeting");
		                        //$.validationEngine.closePrompt("#start");
		                        //$.validationEngine.closePrompt("#end");
		                 },
		                 timeFormat: 'HH:mm{ - HH:mm}',
		                 buttons: {
		                	 "关闭": function () {
		                            $(this).dialog("close");
		                            $("#morningWatchkeeper").val(''); //早班值班人员
	                                $("#nightWatchkeeper").val('');//晚班值班人员
		                     },
		                     "删除": function () {
		                         var aa = window.confirm("警告：确定要删除记录，删除后无法恢复！");
		                         if (aa) {
		                        	 var para = { distributeId:distributeId };
		                        	 $.ajax({
		                        		 type: "POST", //使用post方法访问后台
		                                 url: Global.common.ajaxPath+"/schedulingDistribute/delete.do", //要访问的后台地址
		                                 data: para, //要发送的数据
		                                 success: function (data) {
		                                        //对话框里面的数据提交完成，data为操作结果
		                                	 $('.calendar').fullCalendar('removeEvents', distributeId);
		                                	 $("#morningWatchkeeper").val(''); //早班值班人员
			                                 $("#nightWatchkeeper").val(''); 
		                                 }
		                             });
		                         }
		                         $(this).dialog("close");
		                         $("#morningWatchkeeper").val(''); //早班值班人员
	                             $("#nightWatchkeeper").val('');//晚班值班人员
		                     },
		                     "更新": function () {
		                    	 morningWatchkeeper = $("#morningWatchkeeper").val(); //早班值班人员
		                         nightWatchkeeper = $("#nightWatchkeeper").val(); //晚班值班人员
		                         //var id2;
		                         var startdate = $.fullCalendar.parseDate(selectdate);//时间和日期拼接
		                         //alert(startdate);
		                         //var enddate = $.fullCalendar.parseDate(enddatestr);
		                         var schdata = { distributeId:distributeId ,morningWatchkeeper: morningWatchkeeper, nightWatchkeeper: nightWatchkeeper};
		                         $.ajax({
		                        	 type: "POST", //使用post方法访问后台
		                             url: Global.common.ajaxPath+"/schedulingDistribute/edit.do", //要访问的后台地址
		                             data: schdata, //要发送的数据
		                             success: function (data) {
		                            	 if(morningWatchkeeper){
		                            		 var selectdateArray = selectdate.split("-");
		                            		 var viewStartday2=selectdateArray[2];
		                            		 var viewStartmon2=selectdateArray[1];
		                            		 var viewStartyear2=selectdateArray[0];
		                            		 var schdata2 = { title:'早班：'+morningWatchkeeper ,start:new Date(viewStartyear1,viewStartmon1-1,viewStartday1) };
		                            		 $('.calendar').fullCalendar('renderEvent', schdata2, true);
		                            	 }
		                            	 if(nightWatchkeeper){
		                            		 var selectdateArray = selectdate.split("-");
		                            		 var viewStartday2=selectdateArray[2];
		                            		 var viewStartmon2=selectdateArray[1];
		                            		 var viewStartyear2=selectdateArray[0];
		                            		 var schdata1 = { title:'晚班：'+nightWatchkeeper ,start:new Date(viewStartyear1,viewStartmon1-1,viewStartday1) };
		                            		 $('.calendar').fullCalendar('renderEvent', schdata1, true);
		                            		 
		                            	 }
		                                 $("#morningWatchkeeper").val(''); //早班值班人员
		                                 $("#nightWatchkeeper").val(''); //晚班值班人员
		    				             //location.reload();

		                             }
		                         });
		                         $(this).dialog("close");
		                     }
		                 }
		            });
		            $("#reservebox").dialog("open");
		            return false;
	            });
	        },
	        eventMouseover: function (calEvent, jsEvent, view) {
	        	console.log(calEvent);
                var fstart = $.fullCalendar.formatDate(calEvent.start, "yyyy/MM/dd");
                var fend = $.fullCalendar.formatDate(calEvent.end, "yyyy/MM/dd");
                $(this).attr('title', fstart  + " : " + calEvent.title);
                $(this).css('font-weight', 'normal');
                $(this).tooltip({
                    effect: 'toggle',
                    cancelDefault: true
                });
            },
	        
		});
	}*/

});